<!DOCTYPE html>
<html  xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>网运宝管理系统</title>
	<link th:include="common/header::copy"/>
<style type="text/css">
    .eInfo{
        float:left;
        padding-right: 30px;
        padding-top: 30px;
        color: black;
        font-family: "Cambria Math";
        font-size: large;
    }
    .userInfo{
        float:right;
        padding-right: 30px;
        padding-top: 20px;
        color: black;
        font-family: "Cambria Math";
        font-size: large;
    }
    .logout{
        float:right;
        padding-right: 30px;
        padding-top: 20px;
        color:black;
        font-family: "Cambria Math";
        font-size: large;
    }
    .pwd {
        float:right;
        padding-right: 50px;
        padding-top: 20px;
        color: black;
        font-family: "Cambria Math";
        font-size: large;
    }

</style>

<script type="text/javascript">
	$(document).ready(function() {
		var content = "";
		$("#tabs").tabs("add", {
			title: "首页",
			iconCls: "menu-25",
			closable: false,
			content: content
		});

		$("#tree").tree({
			lines: true,
			url: '/sys/res/menuset',
			method: 'get',
			onLoadSuccess: function () {
				$("#tree").tree("collapseAll");
			},
			onClick: function (node) {
				if (node.id == 6040) {
					openPasswordModifyDialog();
				} else if (node.id == 6050) {
					logout();
				} else if (node.attributes.url) {
					openTab(node);
				}
			}
		});

		// 监听右键事件，创建右键菜单
		$('#tabs').tabs({
			onContextMenu: function (e, title, index) {
				e.preventDefault();
				if (index > 0) {
					$('#menu').menu('show', {
						left: e.pageX,
						top: e.pageY
					}).data("tabTitle", title);
				}
			}
		});

		// 右键菜单click
		$("#menu").menu({
			onClick: function (item) {
				closeTab(this, item.name);
			}
		});

		function closeTab(menu, type) {
			var allTabs = $("#tabs").tabs('tabs');
			var allTabtitle = [];
			$.each(allTabs, function (i, n) {
				var opt = $(n).panel('options');
				if (opt.closable)
					allTabtitle.push(opt.title);
			});
			var curTabTitle = $(menu).data("tabTitle");
			var curTabIndex = $("#tabs").tabs("getTabIndex", $("#tabs").tabs("getTab", curTabTitle));
			switch (type) {
				case "1": // 刷新当前标签页
					var panel = $("#tabs").tabs("getTab", curTabTitle).panel("refresh");
					break;
				case "2": // 关闭当前标签页
					$("#tabs").tabs("close", curTabIndex);
					return false;
					break;
				case "3": // 关闭全部标签页
					for (var i = 0; i < allTabtitle.length; i++) {
						$('#tabs').tabs('close', allTabtitle[i]);
					}
					break;
				case "4": // 关闭其他标签页
					for (var i = 0; i < allTabtitle.length; i++) {
						if (curTabTitle != allTabtitle[i])
							$('#tabs').tabs('close', allTabtitle[i]);
					}
					$('#tabs').tabs('select', curTabTitle);
					break;
				case "5": // 关闭右侧标签页
					for (var i = curTabIndex; i < allTabtitle.length; i++) {
						$('#tabs').tabs('close', allTabtitle[i]);
					}
					$('#tabs').tabs('select', curTabTitle);
					break;
				case "6": // 关闭左侧标签页
					for (var i = 0; i < curTabIndex - 1; i++) {
						$('#tabs').tabs('close', allTabtitle[i]);
					}
					$('#tabs').tabs('select', curTabTitle);
					break;
			}

		}

		function openTab(node) {
			if ($("#tabs").tabs("exists", node.text)) {
				$("#tabs").tabs("select", node.text)
			} else {
				var content = "<iframe frameborder=0 scrolling='auto' style='width:100%;height:99%' src='" + node.attributes.url + "'></iframe>";

				$("#tabs").tabs("add", {
					title: node.text,
					iconCls: node.iconCls,
					closable: true,
					content: content
				});
			}
		}
	});

		function openPasswordModifyDialog() {
			$("#dlg").dialog("open").dialog("setTitle", "修改密码");
		}

		function logout() {
			$.messager.confirm("系统提示", "您确定要退出系统吗?", function (r) {
				if (r) {
					window.location.href = "/logout";
				}
			});
		}

		function modifyPassword() {
			$("#fm").form("submit", {
				url: "/sys/user/updatePassWord",
				method: "post",
				onSubmit: function () {
					var newPassword = $("#newPassword").val();
					var newPassword2 = $("#newPassword2").val();
					if (!$(this).form("validate")) {
						return false;
					}
					if (newPassword != newPassword2) {
						$.messager.alert("系统提示", "确认新密码输入错误！");
						return false;
					}
					return true;
				},
				success: function (result) {
					var result = eval('(' + result + ')');
					if (result.success) {
						$.messager.alert("系统提示", "密码修改成功，下一次登录生效！");
						resetValue();
						$("#dlg").dialog("close");
					} else {
						$.messager.alert("系统提示", "密码输入错误，修改失败！");
					}
				}
			});
		}

		function resetValue() {
			$("#oldPassword").val("");
			$("#newPassword").val("");
			$("#newPassword2").val("");
		};
	
</script>
</head>
<body class="easyui-layout">
<div region="north" style="height: 72px;">
	<table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0"  style="background:url(/images/top_center.jpg)">
		<tr>
			<td class="eInfo">授权使用单位：[[${session.enterprise.getEname()}]]</td>
            <td>
                <a class="logout" href="javascript:logout()" style="text-decoration: none">退出</a>
                <a class="pwd" href="javascript:openPasswordModifyDialog()" style="text-decoration: none">修改密码</a>
                <div  class="userInfo">操作员：[[${session.user.getAccount()}]]</div>
            </td>
		</tr>
	</table>
</div>

<div region="center">
	<div id="tabs" class="easyui-tabs" fit="true" border="false"></div>
</div>

<div region="west" style="width: 200px" title="导航菜单" split="true" iconCls="icon-navigation">
	<ul id="tree" class="easyui-tree" style="padding: 10px"></ul>
</div>

<div region="south" style="height: 30px;padding: 5px" align="center">
	Copyright © 2019-2020 开牛软件 版权所有
</div>

<div id="dlg" class="easyui-dialog" style="width: 400px;height: 180px;padding: 10px 20px"
	closed="true" buttons="#dlg-buttons" data-options="onClose:function(){resetValue()}">
		<form id="fm" method="post">
			<table cellspacing="8px">
                <tr>
                    <td>旧密码：</td>
                    <td>
                        <input type="password" id="oldPassword" name="password" class="easyui-validatebox" required="true" style="width: 200px"/>
                    </td>
                </tr>
				<tr>
					<td>新密码：</td>
					<td>
						<input type="password" id="newPassword" name="newPassword" class="easyui-validatebox" required="true" style="width: 200px"/>
					</td>
				</tr>
				<tr>
					<td>确认新密码：</td>
					<td>
						<input type="password" id="newPassword2" name="newPassword2" class="easyui-validatebox" required="true" style="width: 200px"/>
					</td>
				</tr>
			</table>
		</form>
	</div>
	
	<div id="dlg-buttons">
		<a href="javascript:modifyPassword()" class="easyui-linkbutton" iconCls="icon-ok" >保存</a>
		<a href="javascript:closeDialog('#dlg')" class="easyui-linkbutton" iconCls="icon-cancel" >关闭</a>
	</div>


<div id="menu" class="easyui-menu" >
     <div id="mm-tabrefresh" data-options="name:1,iconCls:'icon-refresh'"> 刷新当前标签页</div>
     <div class="menu-sep"></div>
     <div id="mm-tabclose" data-options="name:2,iconCls:'icon-closetab'">关闭当前标签页</div>
     <div id="mm-tabcloseall" data-options="name:3,iconCls:'icon-closealltab'">关闭全部标签页</div>
     <div id="mm-tabcloseother" data-options="name:4,iconCls:'icon-closeothertab'">关闭其他标签页</div>
     <div id="mm-tabcloseright" data-options="name:5,iconCls:'icon-closerighttab'">关闭右侧标签页</div>
     <div id="mm-tabcloseleft" data-options="name:6,iconCls:'icon-closelefttab'">关闭左侧标签页</div>
 </div>
</body>
</html>